<?php

namespace addons\payment;

use addons\payment\command\Syncfile;
use app\common\library\Menu;
use think\Addons;
use think\Loader;

/**
 * 插件
 */
class Payment extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name' => 'payment',
                'title' => '支付渠道',
                'icon' => 'fa fa-money',
                'ismenu' => 1,
                'sublist' => [
                    [
                        'name' => 'payment/channel',
                        'title' => '支付渠道',
                        'icon' => 'fa fa-circle-o',
                        'ismenu' => 1,
                        'sublist' =>[ 
                            [
                                'name' => 'payment/channel/index',
                                'title' => '查看',
                            ],
                            [
                                'name' => 'payment/channel/recyclebin',
                                'title' => '回收站',
                            ],
                            [
                                'name' => 'payment/channel/add',
                                'title' => '添加',
                            ],
                            [
                                'name' => 'payment/channel/edit',
                                'title' => '编辑',
                            ],
                            [
                                'name' => 'payment/channel/config',
                                'title' => '配置',
                            ],
                            [
                                'name' => 'payment/channel/del',
                                'title' => '删除',
                            ],
                            [
                                'name' => 'payment/channel/destroy',
                                'title' => '真实删除',
                            ],
                            [
                                'name' => 'payment/channel/restore',
                                'title' => '还原',
                            ],
                            [
                                'name' => 'payment/channel/multi',
                                'title' => '批量更新',
                            ]
                        ]
                    ],
                    [
                        'name' => 'payment/order',
                        'title' => '支付订单',
                        'icon' => 'fa fa-circle-o',
                        'ismenu' => 1,
                        'sublist' =>[ 
                            [
                                'name' => 'payment/order/index',
                                'title' => '查看',
                            ],
                            [
                                'name' => 'payment/order/recyclebin',
                                'title' => '回收站',
                            ],
                            [
                                'name' => 'payment/order/add',
                                'title' => '添加',
                            ],
                            [
                                'name' => 'payment/order/pay',
                                'title' => '虚拟支付',
                            ],
                            [
                                'name' => 'payment/order/dohook',
                                'title' => '触发回调',
                            ],
                            [
                                'name' => 'payment/order/destroy',
                                'title' => '真实删除',
                            ],
                            [
                                'name' => 'payment/order/restore',
                                'title' => '还原',
                            ],
                            [
                                'name' => 'payment/order/multi',
                                'title' => '批量更新',
                            ]
                        ]
                    ],
                ]
            ]
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete("payment");
        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {
        Menu::enable("payment");
        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {
        Menu::disable("payment");
        return true;
    }

    /**
     * 添加命名空间
     */
    public function appInit()
    {
        //添加命名空间
        if (!class_exists('\Yansongda\Pay\Pay')) {
            Loader::addNamespace('Yansongda\Pay', ADDON_PATH . 'payment' . DS . 'library' . DS . 'Yansongda' . DS . 'Pay' . DS);
        }
        if (!class_exists('\Yansongda\Supports\Logger')) {
            Loader::addNamespace('Yansongda\Supports', ADDON_PATH . 'payment' . DS . 'library' . DS . 'Yansongda' . DS . 'Supports' . DS);
        }
    }
}
